package listbyorder.access001_100.test14;

/**
 * 官方方法
 *
 * @author code_yc
 * @version 1.0
 * @date 2020/5/27 0:02
 */
public class Solution3 {

    // 直接用str[0]作位基准进行比较
    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0) {
            return "";
        }
        char c;
        for (int i = 0; i < strs[0].length(); i++) {
            c = strs[0].charAt(i);
            for (int j = 1; j < strs.length; j++) {
                if (i == strs[j].length() || strs[j].charAt(i) != c) {
                    return strs[0].substring(0, i);
                }
            }
        }
        return strs[0];
    }
}
